1. Field of the Invention
The present invention relates to a recording apparatus, a recording method, a program for a recording method, and a storage medium that stores a program for a recording method. The present invention is applicable to, for example, digital video cameras. In the present invention, the management information is updated each time a certain amount of data is recorded, and when a storage medium is a flash memory or the like, the certain amount of data is increased according to an increase in an erase-block size. Thus, when records in FAT entries or the like are updated each time the certain amount of data is recorded, a significant reduction in the serviceable life of the storage medium is suppressed.
2. Description of the Related Art
Typically, for recording apparatuses such as digital video cameras, desired data is recorded in various storage media by using FAT (file allocation table) file systems, such as a FAT16 system and FAT32 system. In the FAT file system, a storage area of a storage medium is divided into a data area and a management area, and the data area is managed using management information recorded in the management area for each cluster, which is a management unit of a certain amount of data.
FIG. 15 shows a hierarchical model of a typical system configuration of a FAT file system. The hierarchical model can be broadly divided into a software layer and a hardware layer therebelow. The software layer has layers for processing performed by software, such as programs and various types of firmware and middleware. In the software layer, an application layer (application) 2, a file system layer (file system) 3, and a device driver layer (file system) 4 are sequentially provided from the upper layer. The hardware layer is a layer for a physical configuration including a storage medium 5 and peripheral circuits.
The application layer 2 requests the file system layer 3 to perform recording/reproduction for each certain amount of data. The application layer 2 also obtains, from the file system layer 3, a reply to the request. The file system layer 3 converts an access request, issued from the application layer 2, into an access request for each cluster and outputs the access request to the device driver layer 4. On the basis of a reply for each cluster from the device driver layer 4, the file system layer 3 sends a reply to the request issued from the application layer 2.
The device driver layer 4 converts the each-cluster access request from the file system layer 3 into an access request for each sector, which is a physical management unit in the storage medium, and outputs the access request to the hardware layer. On the basis of a reply to the access request, the device driver layer 4 also sends a reply to the file system 3. In the FAT file system, one cluster is constituted by multiple sectors.
In response to the each-sector access request from the device driver layer 4, the hardware layer reads data from a corresponding sector in the storage medium 5 and outputs the read data to the device driver layer 4. Similarly, the hardware layer writes data to a corresponding sector in the storage medium 5 and sends a reply to the device driver layer 4. The file system layer 3 in this hierarchical model uses a FAT file system, and thus, the storage medium 5 is formatted according to the FAT file system.
FIG. 16 shows the format structure of the storage medium 5 using the FAT file system. Part (A) in FIG. 16 shows FAT16 and part (B) in FIG. 16 shows FAT32. The format structure shown in FIG. 16 also has a logical structure in accordance with LBA (logical block addressing). In FIG. 16, the top stage indicates a first sector (LBA=0) and the sector number increases sequentially toward the bottom stage. In the case shown in FIG. 16, the storage medium has one partition.
In the FAT16, an MBR (master boot record) is provided in the first sector. One sector has 512 bytes. Part (A) in FIG. 17 shows details of data allocated to the MBR in a raster scan order. In part (A) in FIG. 17, a single row has 16 bytes, and representations 0000 to 01F0 shown at the left side in part (A) in FIG. 17 each express an address of first one byte in each row in a hexadecimal representation. Representations 00 to 0F shown at the top each express an address in the row (16 bytes) in a hexadecimal representation.
In part (A) in FIG. 17, startup code is allocated to a 446-byte area of 0000h to 01BDh. The startup code is code for starting up (booting) an OS (operating system) and is provided when a storage medium is used for starting up the OS.
In the MBR, the subsequent 64-byte area from 01BEh to 01FDh has a partition table. In the partition table, the 64-byte area is divided into areas each having 16 bytes and can register four partitions. During startup of each partition, information therefor is recorded. More specifically, as shown in a partition-entry structure in part (B) in FIG. 17, a flag indicating the presence/absence of designation of a startup drive, a partition start sector expressed in a CHS (cylinder/head/sector) representation, a system identifier (type), a partition end sector expressed in a CHS representation, a partition start sector expressed by LBA, and a partition size are sequentially allocated in the partition table. The system identifier indicates a platform, a file system, and so on for the partition. In part (A) in FIG. 17, code (55AA) indicating the last 2 byte of the MBR is set in the MBR.
In the FAT16 (shown in FIG. 16), the MBR is followed by a blank area having a predetermined number of sectors. In the FAT16, an area other than the MBR and the blank area is divided into partitions. In the FAT16, a predetermined first area in each partition is allocated to a system area, which is a management area for a data area provided in the partition and the rest of the area is allocated to the data area of the partition.
In the system area, a first area having a predetermined number of bytes is allocated to a BPB (BIOS Parameter Block/Boot Parameter Block). The BPB records information used, for example, when a BIOS (Basic Input/Output System) or the like of a host accesses a FAT area that follows the BPB. More specifically, the BPB records the number of FAT areas, the start sector of a main FAT area, the number of sectors in the FAT areas, and so on.
In the system area, the BPB is followed by a first FAT area FAT 1 and a second FAT area FAT 2. One of the first FAT area FAT 1 and the second FAT area FAT 2 is set as the main FAT area and the other one is used as a backup reserved area or the like. In the FAT areas FAT 1 and FAT 2, FAT entries of clusters allocated to the data area are set in order of cluster numbers. One of code indicating “unused”, code indicating an EOF (end of file), and the cluster number of a cluster in which data to be reproduced next is recorded is recorded in each FAT entry. The cluster number of a cluster in which data to be reproduced next is recorded will hereinafter be referred to as a “linked cluster number”. The cluster number is a number for identifying an individual cluster allocated to the data area. In the FAT16, the cluster number is expressed in 2 bytes and each FAT entry is expressed in 2 bytes correspondingly.
In the system area, the second FAT area FAT 2 is followed by a root directory entry. The root directory entry has a directory provided in a root directory and directory entries of files. FIG. 18 shows a directory entry. In the directory entry, the name of a corresponding file, an extension, attributes, reserved, creation time, creation date, last access date, high-order 1 byte of the first-cluster number, recording time, recording date, low-order 1 byte of the first-cluster number, and a file size are sequentially allocated. In FIG. 18, upper numerals 0 to 1F indicate the byte position of each piece of data expressed in a hexadecimal representation starting from a value “0”, and lower numerals 1 to 32 indicate the byte position of each piece of data expressed in a decimal representation starting from a value “1”.
As a result, in the FAT16, on the basis of a file name and a extension, a directory entry of a desired file is detected from the directory entries recorded in the root directory entry. On the basis of a first cluster number set in the detected directory entry, a cluster number that identifies a first cluster in which the desired file is recorded is detected. On the basis of linked cluster numbers detected by sequentially searching the records in the FAT entries from the detected first cluster number, the cluster numbers of clusters in which subsequent data is recorded are sequentially detected.
Part (B) in FIG. 16 shows, in comparison with part (A) in FIG. 16, the format structure of the FAT32. The FAT32 has the same structure as the FAT16, except that each cluster is managed in 4 bytes, the directory entries described above in the FAT16 are provided in the data area, the structure related to the directory entries is different, and an FSInfo area is provided in the system area. Thus, in the FAT32, clusters in the data area in which a desired file is recorded are detected on the basis of a first cluster number detected from the directory entries and linked cluster numbers detected by sequentially searching records in the FAT entries from the first cluster number. The FSInfo area stores information used for calculating a blank space in the corresponding partition.
FIG. 19 shows a specific structure of the FAT entries in the FAT32. In FIG. 19, RSV indicates a reserved area and “-” indicates a blank area. In the example shown in FIG. 19, the directory entries of four files are recorded in the data area, and the first-cluster numbers of the directory entries are set to 00000007, 0000000A, 0000001B, and 0000002C. In FIG. 19, linked cluster number 00000008 is recorded in the FAT entry with cluster number 00000007, linked cluster number 00000009 is recorded in the FAT entry with cluster number 00000008, and an EOF is recorded in the FAT entry with cluster number 00000009. Thus, it can be understand that data of the file with first-cluster number 00000007 is sequentially recorded in the clusters with cluster numbers 00000007, 00000008, and 00000009.
In FIG. 19, linked cluster number 0000001F is recorded in the FAT entry with cluster number 0000000A, linked cluster number 00000025 is recorded in the FAT entry with cluster number 0000001F, linked cluster number 00000031 is recorded in the FAT entry with cluster number 00000025, linked cluster number 00000030 is recorded in the FAT entry with cluster number 00000031, and an EOF is recorded in the FAT entry with 00000030. Thus, it can be understand that data of the file with first cluster number 0000000A is sequentially recorded in the clusters with cluster numbers 0000000A, 0000001F, 00000025, 00000031, and 00000030.
Similarly, it can be understood that data of the file with first-cluster number 0000001B is sequentially recorded in the clusters with cluster numbers 0000001B, 00000011, 00000012, 00000013, 00000014, and 00000003 and data of the file with first-cluster number 0000002C is sequentially recorded in the clusters with cluster numbers 0000002C, 0000002D, 0000002E, 0000002F, 00000038, 00000039, 0000003A, and 0000003B.
During data recording, a recording apparatus of the related art searches the FAT area to detect clusters in a blank area. The recording apparatus of the related art sets a first-cluster number and so on on the basis of a result of the detection, records a directory entry, then sequentially records data to the clusters in the blank area, and sequentially records and holds, in an internal memory, the cluster numbers of the clusters to which data is recorded. When the recording of a file is completed, the recording apparatus updates the records in the FAT entries so as to correspond to the recording of the data in accordance with the records in the internal memory, sets linked clusters, and re-records a directory entry.
In connection with processing during the data recording, for example, Japanese Unexamined Patent Application Publication No. 2007-122221 discloses a method for updating records in FAT entries and setting linked clusters each time a certain amount of data is recorded in a data area. According to the method, even when power is shut down during recording of a file, data that has already been recorded can be reproduced. Thus, the method can prevent loss of precious data.
In recent years, memory cards that use flash memories as detachable storage media have been available. In the flash memories, a recording area is divided by erase blocks and data is erased for each erase block. Also, even when part of data in erase blocks is to be updated, the entire data in the erase blocks are updated. More specifically, after data to be updated is recorded to another erase block, the data updating for each erase block is executed by replacing the address of an erase block in which the data has already been recorded with the address of the other erase block.
The flash memory is generally limited in the number of recording operations. Thus, merely updating of records in the FAT entries each time a certain amount of data is recorded in order to prevent loss of precious data has a problem in that the serviceable life of the flash memory is reduced significantly.